package com.zjj.provider.service;

import com.zjj.DemoService;
import com.zjj.DemoServiceListener;
import org.apache.dubbo.config.annotation.Argument;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Service;


// DemoService的sayHello方法的index=1的参数是回调对象，服务消费者可以调用addListener方法来添加回调对象，服务提供者一旦执行回调对象的方法就会通知给服务消费者
//arguments = {@Argument(index = 1, callback = true)})} 的意思是 sayHello方法的第二个参数是回调参数
//callbacks = 3 的意思是这个服务最多支持多少个回调
@Service(version = "default", timeout =1000000  ,  methods = {@Method(name = "sayHello", arguments = {@Argument(index = 1, callback = true)})}, callbacks = 3)
public class CallBackDemoService implements DemoService {



    /**
     * 回调方法
     */
    @Override
    public String sayHello(String name,  DemoServiceListener callback) throws InterruptedException {
        System.out.println("1.开始执行回调服务,参数name是:" + name + "   毫秒值是 :" + System.currentTimeMillis());

        //在执行回调函数
        String rs = callback.changed("我是provider传过去的入参");
        Thread.sleep(1000);


        System.out.println("3.回调的结果是: " + rs  + "   毫秒值是 :" + System.currentTimeMillis());
        return String.format( name);  // 正常访问
    }

}
